package com.cyl.game.demos.web.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Delete;
import java.util.List;
import com.cyl.game.demos.web.entity.Hero; 
import com.cyl.game.demos.web.entity.User; // 根据实际项目包名替换
// 根据实际项目包名替换

@Mapper
public interface HeroMapper {
    // 插入英雄设计信息
    @Insert("INSERT INTO hero_designs (hero_name, hero_skills, appearance, user_id) VALUES (#{hero_name}, #{hero_skills}, #{appearance}, #{user_id})")
    int insertHeroDesign(Hero heroDesign);

    // 根据用户ID查询该用户的所有英雄设计信息
    @Select("SELECT * FROM hero_designs WHERE user_id = #{user_id}")
    List<Hero> selectHeroDesignsByUserId(Integer user_id);

    // 更新英雄设计信息（根据英雄ID更新，可根据实际需求调整条件）
    @Update("UPDATE hero_designs SET hero_name = #{hero_name}, hero_skills = #{hero_skills}, appearance = #{appearance} WHERE hero_id = #{hero_id}")
    int updateHeroDesign(Hero heroDesign);

    // 删除英雄设计信息（根据英雄ID删除，可根据实际需求调整条件）
    @Delete("DELETE FROM hero_designs WHERE hero_id = #{hero_id}")
    int deleteHeroDesign(Integer hero_id);
        // 根据英雄 ID 列表批量查询英雄详细信息（示例方法，可按需调整）
        @Select({
            "<script>",
            "SELECT * FROM hero_designs WHERE hero_id IN",
            "<foreach collection='heroIdList' item='heroId' open='(' close=')' separator=','>",
            "#{heroId}",
            "</foreach>",
            "</script>"
        })
        List<Hero> selectHeroDetailsByHeroIdList(List<Integer> heroIdList);
            // 获取指定英雄被哪些用户所拥有（通过中间关联表查询）
    @Select("SELECT u.* " +
    "FROM hero_designs hd " +
    "JOIN user_hero_relation uhr ON hd.hero_id = uhr.hero_id " +
    "JOIN users u ON uhr.user_id = u.user_id " +
    "WHERE hd.hero_id = #{hero_id}")
List<User> getUsersWhoOwnTheHero(Integer hero_id);
}